﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace Hotnet.Web.Utility
{
	public class CrossDomainCookie : IHttpModule
	{
		private string m_RootDomain = string.Empty;

		#region IHttpModule Members

		public void Dispose()
		{

		}

		public void Init(HttpApplication context)
		{
			m_RootDomain = ConfigurationManager.AppSettings["RootDomain"];
			//m_RootDomain = ".woxx8.com";
			context.EndRequest += new System.EventHandler(context_EndRequest);
		}

		void context_EndRequest(object sender, System.EventArgs e)
		{
			HttpApplication app = sender as HttpApplication;

			for (int i = 0; i < app.Context.Response.Cookies.Count; i++)
			{
				app.Context.Response.Cookies[i].Domain = m_RootDomain;
			}
		}

		#endregion
	}
}
